<html>
<body>

<FORM METHOD = "GET">
<TEXTAREA NAME="query" ROWS=10 COLS=45>
</TEXTAREA>
<INPUT TYPE="submit" VALUE="Done">
</FORM>


<?php

$db_connection = mysql_connect("localhost", "cs143", "");
mysql_select_db("CS143", $db_connection);

$query = $_GET["query"];
if ($query != '')
{
   $rs = mysql_query($query, $db_connection);
   $numCols = mysql_num_fields($rs);
   print "<table border=\"1\" cellspacing=\"1\" cellpadding=\"2\">";
   print "<tr>";   
   for ($col=0; $col<$numCols; $col++)
   {
      echo "<th>" . mysql_field_name($rs, $col) . "</th>";
   }
   while ($row = mysql_fetch_row($rs))
   {
      print "<tr>";
      foreach ($row as $column)
      {
	 if ($column != '')
	 {
            print "<td>$column</td>";
         }
	 else
	 {
	    print "<td>N/A</td>";
	 }
      }
      print "</tr>";
   }
   print "</table>";
}


mysql_close($db_connection);
?>

</body>
</html>
